//
//  HistoryTableViewCell.m
//  My1A2B
//
//  Created by sun ives on 2010/1/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "HistoryTableViewCell.h"
#import "define_tw.h"

#define EDITING_INSET       10.0
#define TEXT_LEFT_MARGIN    8.0
#define TEXT_RIGHT_MARGIN   5.0
#define PREP_TIME_WIDTH     160.0


@implementation HistoryTableViewCell
@synthesize m_uiGuessTime, m_uiStartTime, m_uiAnswer, game;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
	
	if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {		
        m_uiGuessTime = [[UILabel alloc] initWithFrame:CGRectZero];
        [m_uiGuessTime setFont:[UIFont boldSystemFontOfSize:14.0]];
        [m_uiGuessTime setTextColor:[UIColor blackColor]];
        [m_uiGuessTime setHighlightedTextColor:[UIColor whiteColor]];
        [self.contentView addSubview:m_uiGuessTime];
		
        m_uiStartTime = [[UILabel alloc] initWithFrame:CGRectZero];
        [m_uiStartTime setFont:[UIFont systemFontOfSize:12.0]];
        [m_uiStartTime setTextColor:[UIColor darkGrayColor]];
        [m_uiStartTime setHighlightedTextColor:[UIColor whiteColor]];
        [self.contentView addSubview:m_uiStartTime];
		
        m_uiAnswer = [[UILabel alloc] initWithFrame:CGRectZero];
        m_uiAnswer.textAlignment = UITextAlignmentRight;
        [m_uiAnswer setFont:[UIFont systemFontOfSize:13.0]];
        [m_uiAnswer setTextColor:[UIColor blackColor]];
        [m_uiAnswer setHighlightedTextColor:[UIColor whiteColor]];
		//m_uiAnswer.minimumFontSize = 7.0;
		//m_uiAnswer.lineBreakMode = UILineBreakModeTailTruncation;
        [self.contentView addSubview:m_uiAnswer];
		
    }
	
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
	
    [m_uiGuessTime setFrame:[self _guessTimeFrame]];
    [m_uiStartTime setFrame:[self _startTimeFrame]];
    [m_uiAnswer setFrame:[self _answerFrame]];
}
- (CGRect)_guessTimeFrame{
	return CGRectMake(TEXT_LEFT_MARGIN, 4.0, self.contentView.bounds.size.width  - TEXT_RIGHT_MARGIN * 2 - PREP_TIME_WIDTH, 16.0);
}
- (CGRect)_startTimeFrame {
	return CGRectMake(TEXT_LEFT_MARGIN, 22.0, self.contentView.bounds.size.width - TEXT_LEFT_MARGIN, 16.0);
}

- (CGRect)_answerFrame {
    CGRect contentViewBounds = self.contentView.bounds;
    return CGRectMake(contentViewBounds.size.width - PREP_TIME_WIDTH - TEXT_RIGHT_MARGIN, 4.0, PREP_TIME_WIDTH, 16.0);
}

- (void)setGame:(strGame *)currGame{
	NSString *guessTime, *startTime, *answer;
	if (currGame) {
		game = currGame;
		guessTime = [[NSString alloc] initWithFormat:GUESS_TIME, game->guessTime];
		startTime = [[NSString alloc] initWithFormat:START_TIME, game->startTime];
		answer = [[NSString alloc] initWithFormat:ANSWER_COUNT, game->answer, game->count];
	}else {
		guessTime = [[NSString alloc] initWithFormat:@"ERROR"];
		startTime = [[NSString alloc] initWithFormat:@"ERROR"];
		answer = [[NSString alloc] initWithFormat:@"ERROR"];
	}
	m_uiGuessTime.text = guessTime;
	m_uiStartTime.text = startTime;
	m_uiAnswer.text = answer;
	[guessTime release];
	[startTime release];
	[answer release];
}


@end
